{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-05-07T15:32:03.741257700Z",
     "start_time": "2024-05-07T15:32:03.738304500Z"
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"DASHSCOPE_API_KEY\"] = \"sk-edf4bccb72d14fbabcb7f1d9369c8a65\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [],
   "source": [
    "import langchain\n",
    "from langchain_community.llms import Tongyi"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-07T15:34:19.222073700Z",
     "start_time": "2024-05-07T15:34:18.989119300Z"
    }
   },
   "id": "55f5b2fc59d40478"
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "'Justin Bieber was born on March 1, 1994. The Super Bowl that year was Super Bowl XXVIII, which was played on January 30, 1994. The Dallas Cowboys won that Super Bowl, defeating the Buffalo Bills with a score of 30-13.'"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tongyi().invoke(\"What NFL team won the Super Bowl in the year Justin Bieber was born?\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-07T15:34:22.268941900Z",
     "start_time": "2024-05-07T15:34:19.737372300Z"
    }
   },
   "id": "a6201447fd90fc55"
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "春风吹绿江南岸，万物复苏展新颜。\n",
      "桃花嫣红柳青青，芬芳花香满人间。\n",
      "草长莺飞盈野径，蝴蝶翩翩舞花间。\n",
      "春雨绵绵润大地，生机勃发见春暖。\n",
      "\n",
      "樱桃垂丝笑春风，百花争艳似锦绣。\n",
      "农田翠色铺如画，鱼跃浅溪乐悠悠。\n",
      "傍晚牧童归牛群，笛声悠扬在晴空。\n",
      "春天的诗，写在每一寸土地，温暖如诗，明媚如歌。\n",
      "\n",
      "春光乍泄映湖心，泛舟水上享宁静。\n",
      "燕子双飞剪春影，落日余晖洒金屏。\n",
      "春眠不觉晓，处处闻啼鸟，\n",
      "春色满园关不住，一枝红杏出墙来。\n",
      "\n",
      "春天是诗人的灵感，是画家的调色板，\n",
      "是孩子们的欢笑，是恋人的呢喃。\n",
      "让我们拥抱这春的季节，感受生命的脉搏，\n",
      "在每一个清晨和黄昏，吟唱春的赞歌。"
     ]
    }
   ],
   "source": [
    "llm = Tongyi()\n",
    "for chunk in llm.stream(\"写一首关于春天的诗歌\"):\n",
    "    print(chunk, end=\"\", flush=False)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-07T15:36:01.282978300Z",
     "start_time": "2024-05-07T15:35:54.563504200Z"
    }
   },
   "id": "174a7be9aa974cd"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "83164ebaa757651e"
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "17f303239c084c97"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
